package com.itcam.phaselist.list_;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * List三种遍历方式
 */
public class ListFor {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("cammy");
        list.add("jerry");
        list.add("tom");
        list.add("timi");

        // 方式一、使用iterator
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            System.out.print(obj + "\t");
        }

        System.out.println("\n--------------------------------");

        // 方式二、增强for循环
        for (Object obj : list) {
            System.out.print(obj + "\t");
        }

        System.out.println("\n--------------------------------");

        // 方式三、普通for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + "\t");
        }

    }
}
